#pragma once
#include "stream/streambuf.hpp"
#include <istream>

namespace JHCPP
{
	namespace stream
	{
		class CBase64DecodeBuf : public UnbufferedStreamBuf
		{
		public:
			CBase64DecodeBuf(std::istream& istr);
			~CBase64DecodeBuf();

		private:
			int readFromDevice();
			int readOne();

			unsigned char   m_group[3];
			int             m_groupLength;
			int             m_groupIndex;
			std::streambuf& m_buf;

			static unsigned char IN_ENCODING[256];
			static bool          IN_ENCODING_INIT;

		private:
			CBase64DecodeBuf(const CBase64DecodeBuf&);
			CBase64DecodeBuf& operator = (const CBase64DecodeBuf&);
		};


		class CBase64DecodeIOS : public virtual std::ios
		{
		public:
			CBase64DecodeIOS(std::istream& istr);
			~CBase64DecodeIOS();
			CBase64DecodeBuf* rdbuf();

		protected:
			CBase64DecodeBuf m_buf;

		private:
			CBase64DecodeIOS(const CBase64DecodeIOS&);
			CBase64DecodeIOS& operator = (const CBase64DecodeIOS&);
		};


		class CBase64Decode : public CBase64DecodeIOS, public std::istream
		{
		public:
			CBase64Decode(std::istream& istr);
			~CBase64Decode();

		private:
			CBase64Decode(const CBase64Decode&);
			CBase64Decode& operator = (const CBase64Decode&);
		};

	}//end of namespace stream
}//end of namespace JHCPP
